﻿using SFML.Graphics;
using SFML.Window;
using SFML.System;

namespace Midisplay
{
    internal class Program
    {
        static void Main(string[] args)
        {
            RenderWindow window = new RenderWindow(VideoMode.DesktopMode, "Midisplay", Styles.Default);
            window.Size = new Vector2u(1920, 1080);
            window.Resized += (_, e) => window.SetView(new View(new FloatRect(0f, 0f, e.Width, e.Height)));
            Clock clock = new Clock();

            NoteDisplayer displayer = new NoteDisplayer("test.mid", "audio.wav", window.Size.X, window.Size.Y);
            displayer.SetBackground("background.png", window.Size.X, window.Size.Y);

            window.Closed += (_, _) => { displayer.Destroy(); window.Close(); };

            bool isSpaceKeyDown = false;

            while (window.IsOpen)
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.Space))
                {
                    if (isSpaceKeyDown == false)
                    {
                        isSpaceKeyDown = true;
                        displayer.Toggle();
                    }
                }
                else
                {
                    isSpaceKeyDown = false;
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.Left))
                {
                    displayer.Rewind();
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.Right))
                {
                    displayer.Forward();
                }

                displayer.Update(clock.Restart().AsSeconds());

                window.DispatchEvents();

                window.Clear(Color.Black);

                window.Draw(displayer);

                window.Display();
            }
        }
    }
}